package goods

import (
	"context"
	"test-demo/goods_srv/goods"

	"test-demo/api/internal/svc"
	"test-demo/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsListLogic) GoodsList(req *types.GoodsListReq) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.GoodsServer.GoodsList(context.Background(), &goods.GoodsListReq{
		Page:   int64(req.Page),
		Search: req.Search,
	})
	if res.Pong == "0" {
		return &types.Response{
			Code:    10001,
			Message: "获取失败",
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "获取成功",
		Data: map[string]string{
			"data": res.Pong,
		},
	}, nil
}
